<?php 


require "../common/Curl.php";

/**
 *	https=>//open.esign.cn/doc/detail?id=opendoc%2Fpaas_api%2Fsgv49u&namespace=opendoc%2Fpaas_api
 * 	电子签名SaaS API非标版
 * 	流程签署人 + 文本签 + PDF文件验签 ----接口顺序排列封装
 *  使用请求签名鉴权方式
 *  下一个------------------ 区块链核验API block.php
 */



//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * [selectSignersList 流程签署人列表]
 * @param  [type] $flowId [description]
 * @param  [type] $appId  [description]
 * @param  [type] $secret [description]
 * @param  [type] $url    [description]
 * @return [type]         [description]
 */
function selectSignersList($flowId,$appId,$secret,$url){
	$urlss = $url."/v1/signflows/".$flowId."/signers";
	$head_url = "/v1/signflows/".$flowId."/signers";
	$data =[];
    $res = json_encode($data);
    $header = getHeader($data,"GET",$head_url,$appId,$secret);
    $result = sendHttp($method="GET",$urlss,$header,$res);
    return $result;
}
// $flowId = "9a1f67f7f8094d5bbe24ff6927ba4e03";
// $a = selectSignersList($flowId,$appId,$secret,$url);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [rushsign 流程签署人催签]
 * @param  [type] $flowId            [description]
 * @param  [type] $accountId         [description]
 * @param  [type] $noticeTypes       [description]
 * @param  [type] $rushsignAccountId [description]
 * @param  [type] $appId             [description]
 * @param  [type] $secret            [description]
 * @param  [type] $url               [description]
 * @return [type]                    [description]
 */
function rushsign($flowId,$accountId,$noticeTypes,$rushsignAccountId,$appId,$secret,$url){
    $urlss = $url."/v1/signflows/".$flowId."/signers/rushsign";
    $head_url = "/v1/signflows/".$flowId."/signers/rushsign";
	$data =[
		"flowId"=>$flowId,
		"accountId"=>$accountId,
		"noticeTypes"=>$noticeTypes,
		"rushsignAccountId"=>$rushsignAccountId
	];
    $res = json_encode($data);
    $header = getHeader($data,"PUT",$head_url,$appId,$secret);
    $result = sendHttp($method="PUT",$urlss,$header,$res);
    return $result;
}
// $flowId = "9a1f67f7f8094d5bbe24ff6927ba4e03";
// $accountId = "";
// $noticeTypes = "1,2";
// $rushsignAccountId = "24c93459216945468fdf1d899c521910";
// $a = rushsign($flowId,$accountId,$noticeTypes,$rushsignAccountId,$appId,$secret,$url);
// var_dump($a);die;


//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [getExecuteUrl 获取签署地址]
 * @param  [type] $flowId     [description]
 * @param  [type] $accountId  [description]
 * @param  [type] $organizeId [description]
 * @param  [type] $urlType    [description]
 * @param  [type] $appScheme  [description]
 * @param  [type] $appId      [description]
 * @param  [type] $secret     [description]
 * @param  [type] $url        [description]
 * @return [type]             [description]
 */
function getExecuteUrl($flowId,$accountId,$organizeId,$urlType,$appScheme,$appId,$secret,$url){
	$urlss = $url."/v1/signflows/".$flowId."/executeUrl?accountId=".$accountId."&organizeId=".$organizeId;
	$head_url = "/v1/signflows/".$flowId."/executeUrl?accountId=".$accountId."&organizeId=".$organizeId;
	$data =[];
    $res = json_encode($data);
    $header = getHeader($data,"GET",$head_url,$appId,$secret);
    $result = sendHttp($method="GET",$urlss,$header,$res);
    return $result;
}
// $flowId = "9a1f67f7f8094d5bbe24ff6927ba4e03";
// $accountId = "24c93459216945468fdf1d899c521910";
// $organizeId = "2c7de24aff3340f5b944ebac49545b8e";
// $a = getExecuteUrl($flowId,$accountId,$organizeId,$urlType,$appScheme,$appId,$secret,$url);
// var_dump($a);die;


//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// 文本签
/**
 * [textDataSign 平台方&平台用户文本签]
 * @param  [type] $accountId [description]
 * @param  [type] $data      [description]
 * @param  [type] $type      [description]
 * @param  [type] $appId     [description]
 * @param  [type] $secret    [description]
 * @param  [type] $url       [description]
 * @return [type]            [description]
 */
function textDataSign($accountId,$data,$type,$appId,$secret,$url){
	$urlss = $url."/v1/dataSign";
	$head_url = "/v1/dataSign";
    $data = [
		"accountId"=>$accountId,
		"data"=>$data,
	    "type"=>$type
	];
    $res = json_encode($data);
    $header = getHeader($data,"POST",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="POST",$urlss,$header,$res);
    return $result;
}
// $accountId = "ca991b71dcbf461dadfdf245642697ee";
// $data = "测试测试";
// $type = "PLATFORM";
// $a = textDataSign($accountId,$data,$type,$appId,$secret,$url);
// var_dump($a);die; //c49501df-6f59-40a6-9b3b-650cec320a2d

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * [textVerifyDataSign 文本签验签]
 * @param  [type] $data       [description]
 * @param  [type] $signResult [description]
 * @param  [type] $appId      [description]
 * @param  [type] $secret     [description]
 * @param  [type] $url        [description]
 * @return [type]             [description]
 */
function textVerifyDataSign($data,$signResult,$appId,$secret,$url){
	$urlss = $url."/v1/dataSign/verify";
	$head_url = "/v1/dataSign/verify";
    $data = [
		"data"=>$data,
	    "signResult"=>$signResult
	];
    $res = json_encode($data);
    $header = getHeader($data,"POST",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="POST",$urlss,$header,$res);
    return $result;
}
// $data = "测试测试";
// $signResult = "MIIHfwYJKoZIhvcNAQcCoIIHcDCCB2wCAQExDzANBglghkgBZQMEAgEFADALBgkqhkiG9w0BBwGgggVAMIIFPDCCBKWgAwIBAgIIdMQALgBndpgwDQYJKoZIhvcNAQELBQAwYTENMAsGA1UEBh4EAEMATjEPMA0GA1UECB4GbVlsX3cBMQ8wDQYDVQQHHgZnbV3eXgIxGzAZBgNVBAoeEm1ZbF93AWVwW1eLpIvBTi1fwzERMA8GA1UEAx4IAFoASgBDAEEwHhcNMjEwODMxMDgxNjQxWhcNMjIwODMxMDgxNjQxWjB2MQswCQYDVQQGEwJDTjELMAkGA1UECAwCemoxCzAJBgNVBAcMAmh6MRYwFAYDVQQUDA0wNTcxLTg1Nzg1MjIzMTUwMwYDVQQDDCzmtYvor5UgX+axn+ilv+a4heiDvemrmOenkeaKgOacr+aciemZkOWFrOWPuDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAIeaT1n+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ZpY2F0ZT9iYXNlP29iamVjdENsYXNzPWNlcnRpZmljYXRpb25BdXRob3JpdHkwHQYDVR0OBBYEFNro+ow4pP9k66uLgYPPbgbcIVqCMA0GCSqGSIb3DQEBCwUAA4GBABO3AyrwC5HQNP+ji+WJBBeF7m3ZuFiWOMwFd/RqG/OfCisgjHd3spJpeImrFoZF7mo8nknqlOLLBXpFQq50p+2nuqj2Ai4SYDO6CPnlCFR8iE+jUjKL3dQNmrpYX3jj8KEviRU7O7c9VMUZTZ2kSPAB9i5egWct45UEmaM30vUiMYICAzCCAf8CAQEwbTBhMQ0wCwYDVQQGHgQAQwBOMQ8wDQYDVQQIHgZtWWxfdwExDzANBgNVBAceBmdtXd5eAjEbMBkGA1UECh4SbVlsX3cBZXBbV4uki8FOLV/DMREwDwYDVQQDHggAWgBKAEMAQQIIdMQALgBndpgwDQYJYIZIAWUDBAIBBQCgaTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0yMTA4MzEwODE2NDJaMC8GCSqGSIb3DQEJBDEiBCDQH7ZjG6XaDq9VL6vOlFNztepQaOtA6dQV7wC9ZIxC0DANBgkqhkiG9w0BAQEFAASCAQAECLF/f5ByYL8FlJC1LTH9OAWdTj/cZma4k8lRkMENAajR4g4q++0W29J0FD981kq+AYeL2FLdSDN3HmfzVYD2dQAY/xJuY12wFSLuBlAltAL7LCYh6t4Hr3yFcLbGQIn1lqi4G1Y4QMqCZi/mxYp0ZXD4EBLkNa7SamTWGIT8UySnaAE7rqQsLWpiGCNIsCIaLr4nDuqKjW8CPtEeDGo4Q89sjC6oY61xEasGwRJXL8tSFekphXFZxiAbMvqCctINAMBGMrZOaBxOXEYHBWeyXG4doHH+B+oQ8ex/p0PBdKLJDttcZjUA1TF8BTr+SOXo326ieZorhBDnrnZz4lU6\n";
// $a = textVerifyDataSign($data,$signResult,$appId,$secret,$url);
// var_dump($a);die;


//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// PDF文件验签
/**
 * [pdfVerify pdf文件验签]
 * @param  [type] $fileId [description]
 * @param  [type] $flowId [description]
 * @param  [type] $appId  [description]
 * @param  [type] $secret [description]
 * @param  [type] $url    [description]
 * @return [type]         [description]
 */
function pdfVerify($fileId,$flowId,$appId,$secret,$url){
	$urlss = $url."/v1/documents/".$fileId."/verify?flowId=".$flowId;
	$head_url = "/v1/documents/".$fileId."/verify?flowId=".$flowId;
	$data =[];
    $res = json_encode($data);
    $header = getHeader($data,"GET",$head_url,$appId,$secret);
    $result = sendHttp($method="GET",$urlss,$header,$res);
    return $result;
}
// $fileId = "f34a02f8a04b415e8e5a0d5a2";
// $flowId = "6cca7a040d1a6bdff5ea9cc60a7";
// $a = pdfVerify($fileId,$flowId,$appId,$secret,$url);
// var_dump($a);die;



